package com.engine4cloud.tdf.supervision.convert;

import com.engine4cloud.tdf.common.core.constant.enums.WorkerFileTypeEnum;
import com.engine4cloud.tdf.common.security.service.TdfUser;
import com.engine4cloud.tdf.supervision.dto.GzryFileDTO;
import com.engine4cloud.tdf.supervision.dto.query.GzryFileQueryDTO;
import com.engine4cloud.tdf.supervision.entity.GzryFileEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface GzryFileConvert {
    GzryFileConvert INSTANCE = Mappers.getMapper(GzryFileConvert.class);

    @Mapping(target = "id", ignore = true)
    GzryFileEntity createTo(GzryFileDTO s);

    GzryFileDTO convert(GzryFileEntity s);

    default GzryFileEntity create(String code, GzryFileDTO file, WorkerFileTypeEnum fileType, TdfUser u) {
        GzryFileEntity entity = createTo(file);
        entity.setRybm(code);
        entity.setFileType(fileType);
        entity.setTenantId(u.getTenantId());
        return entity;
    }

    default List<GzryFileEntity> createList(GzryFileQueryDTO dto, List<GzryFileDTO> fileList, TdfUser u) {
        return fileList.stream().map(file -> GzryFileConvert.INSTANCE.create(dto.getRybm(), file, dto.getFileType(), u)).toList();
    }
}
